/************************************************************
wx
2020/1/18

*************************************************************/

using AutoJsonClass;

namespace Fight
{
    public class Card
    {
        private static int realIdIndex = 0;

        public string Name { get; private set; }
        public int Consume { get; private set; }
        public int Id { get; private set; }
        public int RealId { get; private set; }
        public CardType Type { get; private set; } = CardType.None;
        public Skill Skill { get; private set; }
        public FightProp Prop { get; private set; }
        public byte Dest { get; private set; }

        public Card(Skill skill)
        {
            if (skill != null)
            {
                Skill = skill;
                Type = CardType.Skill;
                Id = Skill.Id << 16;
                Name = Skill.Name;
                Dest = Skill.Dest;
                Consume = skill.MpConsume;
                RealId = ++realIdIndex;
            }
        }

        public Card(FightProp prop)
        {
            if (prop != null)
            {
                Prop = prop;
                Type = CardType.Prop;
                Id = Prop.Id;
                Name = Prop.Name;
                Dest = Prop.Dest;
                Consume = 0;
                RealId = ++realIdIndex;
            }
        }

        /// <summary>
        /// 攻击到伤害的转化率
        /// </summary>
        public float GetDemageRate()
        {
            switch (Type)
            {
                case CardType.Skill:
                    return Skill.Rate;
            }

            return 0;
        }

        /// <summary>
        /// 计算造成的伤害（不包括基础攻击力的伤害，考虑护甲）
        /// </summary>
        public int GetDemage()
        {
            int demage = 0;
            switch (Type)
            {
                case CardType.Prop:
                {
                    if (Prop != null && Prop.CheckDef == 1)
                    {
                        demage += Prop.Atk;
                    }
                }
                    break;
            }
            return demage;
        }

        /// <summary>
        /// 计算造成的伤害（忽略护甲）
        /// </summary>
        public int GetDemageNoDefend()
        {
            int demage = 0;
            switch (Type)
            {
                case CardType.Prop:
                {
                    if (Prop != null && Prop.CheckDef == 0)
                    {
                        demage += Prop.Atk;
                    }
                }
                    break;
            }
            return demage;
        }

        public int GetDefendChange()
        {
            switch (Type)
            {

            }
            return 0;
        }

        public int GetAttackChange()
        {
            return 0;
        }

        /// <summary>
        /// 获取状态触发概率
        /// </summary>
        public float GetStateRate()
        {
            switch (Type)
            {
                case CardType.Skill:
                {
                    if (Skill.StateRate <= 0 || Skill.StateRate > 1)
                    {
                        return 0;
                    }

                    return Skill.StateRate;
                }
            }

            return 0;
        }

        /// <summary>
        /// 获取附加状态
        /// </summary>
        public FightStatus GetAddState()
        {
            switch (Type)
            {
                case CardType.Skill:
                {
                    return (FightStatus) Skill.StateId;
                }
            }

            return FightStatus.None;
        }

        /// <summary>
        /// 获取附加伤害的概率
        /// </summary>
        public float GetAddDemageRate()
        {
            switch (Type)
            {
                case CardType.Skill:
                {
                    if (Skill.AddRate <= 0 || Skill.AddRate > 1)
                    {
                        return 0;
                    }

                    return Skill.AddRate;
                }

            }
            return 0;
        }

        /// <summary>
        /// 获取附加伤害值
        /// </summary>
        public int GetAddDemage()
        {
            switch (Type)
            {
                case CardType.Skill:
                {
                    return Skill.AddDemage;
                }

            }
            return 0;
        }

        /*
        public static Card GenerateCard(int index)
        {
            if (index <= 0 || index >= (int)CardType.Max)
            {
                return null;
            }

            return GenerateCard((CardType) index);
        }

        public static Card GenerateCard(CardType type)
        {
            switch (type)
            {
                case CardType.Prop:
                    return new SkillCard();
                case CardType.Skill:
                    return new SkillCard();
            }

            return null;
        }*/
        //public abstract bool OnUse();
    }

    //方便填表
    public enum CardType
    {
        None = 0,
        Skill = 1,
        Prop = 2,
        Max
    }
}
